<template>
  <div class="content-card">
    <div class="title">
      <a-icon type="tags"></a-icon>
      <span>{{ "热点应用访问量" }}</span>
    </div>
    <div class="body">
      <div class="child-item">
        <span class="label">{{ name1 }}</span>
        <div class="value">
          <img src="@/assets/img/develop/5-1.jpg" alt="5-1" />
          <span>{{ myCity }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ name2 }}</span>
        <div class="value">
          <img src="@/assets/img/develop/5-2.jpg" alt="5-2" />
          <span>{{ policy }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ name3 }}</span>
        <div class="value">
          <img src="@/assets/img/develop/5-3.jpg" alt="5-3" />
          <span>{{ proper }}</span>
        </div>
      </div>
      <div class="child-item">
        <span class="label">{{ name4 }}</span>
        <div class="value">
          <img src="@/assets/img/develop/5-4.jpg" alt="5-4" />
          <span>{{ xxx }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import API from "@/api/develop";
export default {
  name: "d5-card",
  data() {
    return {
        myCity: 0,
        policy: 0,
        proper: 0,
        xxx: 0,
        name1: '',
        name2: '',
        name3: '',
        name4: ''
    }
  },
  methods: {
      getBoxData() {
          let handleV1 = (res) => (this.setdata(res.data.body.data));
          API.getrdyyywl().then(handleV1);
      },
      setdata(a) {
          this.myCity = a[0].num;
          this.policy = a[1].num;
          this.proper = a[2].num;
          this.xxx = a[3].num;
          this.name1 = a[0].app_name;
          this.name2 = a[1].app_name;
          this.name3 = a[2].app_name;
          this.name4 = a[3].app_name;

      },
      getTask() {
          return () => {
              this.getBoxData();
          };
      },
  },
  mounted() {
      this.getTask()(); // 先执行 一次任务
      this.timer = setInterval(this.getTask(), 30000); // 设置周期触发任务
  },
  beforeDestroy() {
      clearInterval(this.timer);
      this.timer = null;
  },
};
</script>

<style lang="less" scoped>
.content-card {
  .title {
    display: flex;
    align-items: center;
    padding: 10px 0;
    background: linear-gradient(to right, #dee9ff, #ffffff);
    i {
      color: #6989c6;
      margin: 0 15px;
      font-size: 18px;
    }
    span {
      font-size: 16px;
      font-weight: 500;
    }
  }
  .body {
    width: 100%;
    height: 220px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    padding: 10px 5px;
    .child-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      font-size: 16px;
      .label {
        color: #666;
        font-size: 14px;
        margin-bottom: 10px;
      }
      .value {
        display: flex;
        justify-content: center;
        img {
          margin-right: 4px;
          width: 28px;
          height: 28px;
        }
        :last-child {
          font-size: 24px;
        }
      }
      &:nth-child(1) {
        border-right: 1px dashed #eee;
        border-bottom: 1px solid #eee;
        .value :last-child {
          color: #618ec3;
        }
      }
      &:nth-child(2) {
        border-bottom: 1px solid #eee;
        .value :last-child {
          color: #c4595b;
        }
      }
      &:nth-child(3) {
        border-right: 1px dashed #eee;
        .value :last-child {
          color: #b29372;
        }
      }
      &:nth-child(4) {
        .value :last-child {
          color: #0099e2;
        }
      }
    }
  }
}
</style>
